package control.Utils;

import java.awt.geom.Line2D;

import model.Vertex3f;

public class AngleCalculus {
	
	public static float getAngleBetweenXAndLine(Line2D l) {
			return (float) Math.toDegrees(Math.atan2(l.getY2() - l.getY1(), l.getX2() - l.getX1())) + 90;		
	}
	
	
	public static float getAngleBetween2Vertexes(Vertex3f v1, Vertex3f v2) {
		if (v1.z == v2.z) {
			return 0;
		}
		double adist = AngleCalculus.getDistance3D(v1, v2);
		double ddist = Math.sqrt(Math.pow(v1.x - v2.x, 2) + Math.pow(v1.y - v2.y, 2)); //odl miedzy a i b nie uwzgledniajac poziomu(z)
		
		return (float) (v1.z > v2.z ? Math.toDegrees(Math.acos(ddist/adist)): Math.toDegrees(Math.acos(ddist/adist)));
	}
	
	public float getDistance2D(float x1, float y1, float x2, float y2) {
		return (float) (Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2)));
	}
	
	public static float getDistance3D(Vertex3f v1, Vertex3f v2) {
		return (float) Math.sqrt(Math.pow(v1.x - v2.x, 2) + Math.pow(v1.y - v2.y, 2) + Math.pow(v1.z - v2.z, 2));
	}
	
	
}
